<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="generator" content="PHPDoctor 2RC4 (http://peej.github.com/phpdoctor/)">
<meta name="when" content="Mon, 02 May 2011 02:46:56 +0000">

<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="start" href="../overview-summary.html">

<title>phrase.php (Cornice)</title>

</head>
<body id="file" onload="parent.document.title=document.title;">

<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\phrase.php.html" target="_top">No frames</a>
</div>
<hr>

<h1>phrase.php</h1>
<div class="comment" id="overview_description"><p>============================================================================
Cornice PHP Framework & Website Builder
Freeware (f) 2011 by Inforo Software & Computer
============================================================================</p></div>

<hr>

<a name="line1"></a><pre><?php
<a name="line2"></a>/**
<a name="line3"></a> *============================================================================
<a name="line4"></a> * Cornice PHP Framework & Website Builder
<a name="line5"></a> * Freeware (f) 2011 by Inforo Software & Computer
<a name="line6"></a> *============================================================================
<a name="line7"></a> */
<a name="line8"></a> 
<a name="line9"></a>/**
<a name="line10"></a> * Class used as translator for phrases
<a name="line11"></a> * @author Nicola Dinh
<a name="line12"></a> * @version 2011.04.2312
<a name="line13"></a> */
<a name="line14"></a>class phrase {
<a name="line15"></a>
<a name="line16"></a>  /*
<a name="line17"></a>   * All properties
<a name="line18"></a>   */
<a name="line19"></a>  private static $phrases = array();
<a name="line20"></a>  private static $langs = array();
<a name="line21"></a>
<a name="line22"></a>  /**
<a name="line23"></a>   * Default instance level constructor
<a name="line24"></a>   * Just decorative, should not be called due to having only static methods
<a name="line25"></a>   */
<a name="line26"></a>  public function __construct() {
<a name="line27"></a>    //
<a name="line28"></a>  }
<a name="line29"></a>  
<a name="line30"></a>  /**
<a name="line31"></a>   * Load phrases & initialise
<a name="line32"></a>   */
<a name="line33"></a>  public static function initialise() {
<a name="line34"></a>    self::$langs = config::get_supported_langs();
<a name="line35"></a>    if (data::file_exists("phrases"))
<a name="line36"></a>      self::$phrases = data::load_from_file("phrases"); 
<a name="line37"></a>  }
<a name="line38"></a>  
<a name="line39"></a>  /**
<a name="line40"></a>   * Save all phrases back to data file
<a name="line41"></a>   */
<a name="line42"></a>  public static function save_all() {
<a name="line43"></a>    data::save_to_file("phrases",self::$phrases);
<a name="line44"></a>  }
<a name="line45"></a>  
<a name="line46"></a>  /**
<a name="line47"></a>   * Get all loaded phrases
<a name="line48"></a>   * @return array The multi-level array containing all loaded phrases
<a name="line49"></a>   */
<a name="line50"></a>  public static function get_loaded_phrases() {
<a name="line51"></a>    return self::$phrases;
<a name="line52"></a>  }
<a name="line53"></a>  
<a name="line54"></a>  /**
<a name="line55"></a>   * Set a translation for certain phrase
<a name="line56"></a>   * @param string $phrase_uk The english phrase
<a name="line57"></a>   * @param string $lang The language of translated phrase
<a name="line58"></a>   * @param string $phrase_other The phrase in $lang language
<a name="line59"></a>   */
<a name="line60"></a>  public static function set_phrase($phrase_uk,$lang,$phrase_other) {
<a name="line61"></a>    $phrase_uk = trim($phrase_uk);
<a name="line62"></a>    $lang = trim($lang);
<a name="line63"></a>    $phrase_other = trim($phrase_other);
<a name="line64"></a>    $langs = self::$langs;    
<a name="line65"></a>    
<a name="line66"></a>    //add if not existing
<a name="line67"></a>    if (!isset(self::$phrases[$phrase_uk]))
<a name="line68"></a>      self::$phrases[$phrase_uk] = array();
<a name="line69"></a>    foreach ($langs as $abbreviation=>$lang_name) 
<a name="line70"></a>      if (!isset(self::$phrases[$phrase_uk][$abbreviation])) 
<a name="line71"></a>        self::$phrases[$phrase_uk][$abbreviation] = $phrase_uk;
<a name="line72"></a>        
<a name="line73"></a>    //set translated phrase
<a name="line74"></a>    self::$phrases[$phrase_uk][$lang] = $phrase_other;
<a name="line75"></a>  }
<a name="line76"></a>  
<a name="line77"></a>  /**
<a name="line78"></a>   * Translate into current language
<a name="line79"></a>   * @param string $text The text to translate
<a name="line80"></a>   * @return string The text translated into current language
<a name="line81"></a>   */
<a name="line82"></a>  public static function __($text) {
<a name="line83"></a>    $langs = self::$langs;
<a name="line84"></a>    $cur_lang = helper::get_cur_lang();   
<a name="line85"></a>    
<a name="line86"></a>    //add phrase if in devmode & not exists
<a name="line87"></a>    if (system::$devmode) {
<a name="line88"></a>      if (!isset(self::$phrases[$text]))
<a name="line89"></a>        self::$phrases[$text] = array();
<a name="line90"></a>      foreach ($langs as $abbreviation=>$lang) 
<a name="line91"></a>        if (!isset(self::$phrases[$text][$abbreviation])) 
<a name="line92"></a>          self::$phrases[$text][$abbreviation] = "???";
<a name="line93"></a>    }
<a name="line94"></a>  
<a name="line95"></a>    //check if phrase exists in data file
<a name="line96"></a>    if (!isset(self::$phrases[$text])) 
<a name="line97"></a>      return $text;
<a name="line98"></a>      
<a name="line99"></a>    //check if the phrase exists in current language
<a name="line100"></a>    if (!isset(self::$phrases[$text][$cur_lang])) 
<a name="line101"></a>      return $text;
<a name="line102"></a>    
<a name="line103"></a>    //found matching phrase in current language
<a name="line104"></a>    $phrase = trim(self::$phrases[$text][$cur_lang]); 
<a name="line105"></a>    if (strlen($phrase)>0 && $phrase!="???")
<a name="line106"></a>      return $phrase;
<a name="line107"></a>    else
<a name="line108"></a>      return $text;    
<a name="line109"></a>  }
<a name="line110"></a>}</pre>
<div class="header">
<h1>Cornice</h1>
<ul>
<li><a href="../overview-summary.html">Overview</a></li>
<li>Package</li><li>Class</li><li>Tree</li><li><a href="../overview-files.html">Files</a></li>
<li><a href="../deprecated-list.html">Deprecated</a></li>
<li><a href="../todo-list.html">Todo</a></li>
<li><a href="../index-all.html">Index</a></li>
</ul>
</div>

<div class="small_links">
<a href="../index.html" target="_top">Frames</a>
<a href="../source\phrase.php.html" target="_top">No frames</a>
</div>
<hr>

<p id="footer">This document was generated by <a href="http://peej.github.com/phpdoctor/">PHPDoctor: The PHP Documentation Creator</a></p>

</body>

</html>